{template header}
<style type="text/css">
    .bg{display:none;position:fixed;width:100%;height:100%;background:#000;z-index:2;top:0;left:0;opacity:0.7;}
</style>
<h4 style="padding-left:10px;;">
    <a href="?c=adminErp&a=getErpProductList"><span>库存列表</span></a>
    >>
    <a href="?c=adminErp&a=getStockCheck&pid={$productInfo['id']}"><span>盘点</span></a>
</h4>
<div class="control-group" style="margin:0;">
    <label class="control-label" >货品编号：{$productInfo['code']} </label>
    <label class="control-label" >货品名称：{$productInfo['title']} </label>
    </div>
</div>

<div class="bs-docs-example table-align pt-15" style="clear:both;">
    <form class="form-horizontal" method="POST" action="?c=adminErp&a=addStockCheck" id="form1" >
        <table class="table table-striped table-align" border="1" style="width: 90%; margin-left: 100px;">
        <thead>
        <tr>
            <th>规格</th>
            <th>理论库存</th>
            <th>实际库存</th>
            <th>原因</th>
        </tr>
        </thead>
        {if count($list)>0}
        <tbody>
        {loop $list $k $v}
            <tr>
                <td style="display: none"><input type="checkbox" name="gid[$k]" class="gidInput" value="{$v['id']}" ></td>
                <td>{$v['attrPathName']}</td>
                <td>{$v['real_stock_num']}</td>
                <td><input type="text" name="stockNum[$k]" class="stockNumInput" placeholder="请输入实际库存"></td>
                <td><input type="text" name="remark[$k]" class="remarkInput" placeholder="请输入盘点原因"></td>
            </tr>

        {/loop}
        <tr><td colspan="5"> <span class="btn btn-primary" id="addCt">确定</span></td></tr>
        <div id="res"></div>
        </tbody>

        {/if}
    </table>

     </form>
</div>
<div class="pagination">
    <ul>
    </ul>
</div>
{template footer}
<div class="bg" id="bgx"></div>
<div id="dialog" style="position: absolute; z-index: 1003;background-color:white; display: none;" >
    <div  style="margin:50px 100px;">
        <div class="controls">
            <div style="padding-left:20px;">确定操作？</div><br />
            <div style="text-align: center">
               <button class="btn btn-primary" id="ok" ids="">确定</button>
               <button class="btn btn-primary" id="close" >取消</button>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    //$("#bgx").show();
    //letDivCenter('#loading');
    $(function(){
//        $('.stockNumInput').on('change', gidCheck);
//        $('.remarkInput').on('change', gidCheck);
//
//        function gidCheck() {
//
//        }
        $('.stockNumInput').on('change',function(){
            var _this = $(this);
            if ($.trim(_this.val())) {
                _this.parent().siblings().find(".gidInput").prop('checked',true);
            } else {
                var _tx = _this.parent().siblings().find('.remarkInput').val();
                if(!_tx) {
                    _this.parent().siblings().find('.gidInput').prop('checked',false);
                }
            }
        })

        $('.remarkInput').on('change',function(){
            var _this = $(this);
            if ($.trim(_this.val())) {
                _this.parent().siblings().find('.gidInput').prop('checked',true);
            } else {
                var _tx = _this.parent().siblings().find('.stockNumInput').val();
                if(!_tx) {
                    _this.parent().siblings().find('.gidInput').prop('checked',false);
                }
            }
        })
    });

    $('#addCt').on('click',function(){
        $("#bgx").show();
        $('#ok').attr({ids:''});
        letDivCenter('#dialog');
    })

    $('#ok').on('click',function(){
        var _this = $(this);
        $.ajax({
            type:'POST',
            url:$('#form1').attr('action'),
            data:$('#form1').serialize(),
            dataType:'json',
            success:function(d){
                if(d.status=='ok'){
                    alert(d.error_msg);
                    window.location.href= d.url;
                }else{
                    $('#close').click();
                    alert(d.error_msg);
                }
            }
        })
    })
    $('#close').on('click',function(){
        $('#dialog').css('display','none');
        $("#bgx").fadeOut(300);
    })
    function letDivCenter(divName){
        var divObj = $(divName);
        var wWidth = $(document.body).width(),wHeight = $(window).height();
        var divWidth = divObj.width(),divHeight = divObj.height();
        divObj.css({'left':(wWidth-divWidth)/2+$(window).scrollLeft(),'top':(wHeight-divHeight)/2+$(window).scrollTop(),'display':'block'});
        $(window).bind('scroll resize',function(){
            $(divName).css({'left':(wWidth-divWidth)/2+$(window).scrollLeft(),'top':(wHeight-divHeight)/2+$(window).scrollTop()});
        });
    }

</script>